<?php
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use Session;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Service\Admin\AdminService;

class AdminController extends Controller
{


    /**
     * @return $this
     * 管理员列表
     */
    public function getAdminList()
    {
        $where = [];
        $where['token'] = Session::get('MEMBER_TOKEN');

        $admin = new AdminService();

        $data = $admin->getAdminList($where);

        if($data['error_code'] ==0)
        {
            $data = $data['data'];
        }else{
            echo "<script>confirm('{$data['error_message']}')?location.href='/index' : history.back() ;</script>";
            exit();
        }
        return view('Admin.list')->with('data',$data);
    }



    /**
     * @param Request $request
     * 管理员信息更新
     */
    public function doAdminUpdate(Request $request)
    {

        $where = [];
        $where = $request->except('_token');


        $admin = new AdminService();

        $data = $admin->doAdminUpdate($where);


        if($data['error_code'] == '0')
        {
            echo '<script>location.href="/admin";alert("管理员信息修改成功！");</script>';
        }else{
            echo "<script>confirm('{$data['error_message']}')?location.href='/admin' : history.back() ;</script>";
            exit();
        }

    }

    /**
     * @param Request $request
     * 管理员充值
     */
    public function doAdminRecharge(Request $request)
    {
        $where = [];
        $where['money'] = $request->input('money');
        $where['manage_id'] = $request->input('id');

        $admin = new AdminService();
        $data = $admin->doAdminRecharge($where);

        return $data;

    }

    /**
     * @param Request $request
     * @return bool|mixed|string
     * 管理员删除
     */
    public function doAdminDelete(Request $request)
    {
        $where = [];
        $where['manage_id'] = $request->input('id');


        $admin = new AdminService();
        $data = $admin->doAdminDelete($where);

        return $data;
    }


    /**
     * @param Request $request
     * 添加管理员
     */
    public function doAdminAdd(Request $request)
    {
        $where = [];

        $where = $request->except('_token');

        $admin = new AdminService();
        $data = $admin->doAdminAdd($where);

        if($data['error_code'] == '0')
        {
            echo '<script>location.href="/admin";alert("管理员添加成功！");</script>';
        }else{
            echo "<script>confirm('{$data['error_message']}')?location.href='/admin' : history.back() ;</script>";
            exit();
        }


    }



























}